clear all
use "datasets/MRA_waste_sites"

*-------------------------------------------------------------------------------
* TABLE 4 : Baseline meta-regression results
*-------------------------------------------------------------------------------

* Due to manual WLS-RE, every regression composes of the same repeating steps that involve generating 'new' variables starting from the 'metareg' results. This results in lengthy codelines but is considered necessary for manual WLS-RE. For the same reason, the resulting tables using 'outreg2' have to be manually altered to give the same format as the published tables. The coefficients are, of course, identical.

*------------------------------------------------------------------------------*
*WLS-RE PEESE (Baseline)
*------------------------------------------------------------------------------*

quietly metareg elas elas_var publish year_publish_c site_m NPL_n NPL_y NPL_u active_n active_u job_n job_u non_haz nuclear air water element_u North_America Asia Other_continent cleanup0 cleanup2 cleanup3 cleanup_unclear dist_greater_mean sample_c sale_ind num_expl_c oth_disamen oth_amen access industry demoecon time_control direction interaction log_log OLS_spatial, wsse(elas_SE) tau2test

scalar tau2 = e(tau2)
display tau2
gen elas_var_1= elas_var + tau2
gen elas_SE_1 = sqrt(elas_var_1)
gen precision_1= 1/(elas_SE_1)
gen precision_sq_1= 1/elas_var_1

foreach var in elas elas_SE elas_var publish year_publish_c site_m NPL_n NPL_y NPL_u active_n active_u job_n job_u non_haz nuclear air water element_u North_America Asia Other_continent cleanup0 cleanup2 cleanup3 cleanup_unclear dist_greater_mean sample_c sale_ind num_expl_c oth_disamen oth_amen access industry demoecon time_control direction interaction log_log OLS_spatial{
gen `var'1 = `var'/elas_SE_1
}

reg elas1 precision_1 elas_var1 publish1 year_publish_c1 site_m1 NPL_n1 NPL_y1 NPL_u1 active_n1 active_u1 job_n1 job_u1 non_haz1 nuclear1 air1 water1 element_u1 North_America1 Asia1 Other_continent1 cleanup01 cleanup21 cleanup31 cleanup_unclear1 dist_greater_mean1 sample_c1 sale_ind1 num_expl_c1 oth_disamen1 oth_amen1 access1 industry1 demoecon1 time_control1 direction1 interaction1 log_log1 OLS_spatial1, nocons cluster(ID_Study)
outreg2 using "tables/Table 4.rtf", dec(3) replace  ctitle(WLS-RE PEESE) 

*------------------------------------------------------------------------------*
*WLS-FE PEESE
*------------------------------------------------------------------------------*

foreach var in elas elas_SE elas_var publish year_publish_c site_m NPL_n NPL_y NPL_u active_n active_u job_n job_u non_haz nuclear air water element_u North_America Asia Other_continent cleanup0 cleanup2 cleanup3 cleanup_unclear dist_greater_mean sample_c sale_ind num_expl_c oth_disamen oth_amen access industry demoecon time_control direction interaction log_log OLS_spatial{
gen `var'2 = `var'*log_precision
}

reg elas2 elas_var2 log_precision publish2 year_publish_c2 site_m2 NPL_n2 NPL_y2 NPL_u2 active_n2 active_u2 job_n2 job_u2 non_haz2 nuclear2 air2 water2 element_u2 North_America2 Asia2 Other_continent2 cleanup02 cleanup22 cleanup32 cleanup_unclear2 dist_greater_mean2 sample_c2 sale_ind2 num_expl_c2 oth_disamen2 oth_amen2 access2 industry2 demoecon2 time_control2 direction2 interaction2 log_log2 OLS_spatial2, nocons cluster(ID_Study)
outreg2 using "tables/Table 4.rtf", append ctitle(WLS-FE PEESE) dec(3)

*------------------------------------------------------------------------------*
*General-to-specific: Stepwise deleting the least significant variable until only significant variables remain. Not possible for categorical variables unless all are insignificant
*------------------------------------------------------------------------------*

quietly metareg elas elas_var year_publish_c site_m active_n active_u non_haz nuclear air water element_u cleanup0 cleanup2 cleanup3 cleanup_unclear dist_greater_mean sample_c demoecon interaction , wsse(elas_SE) tau2test

scalar tau2 = e(tau2)
display tau2
gen elas_var_3 = elas_var + tau2
gen elas_SE_3 = sqrt(elas_var_3)
gen precision_sq_3 = 1/elas_var_3
gen precision_3 = sqrt(precision_sq_3)

foreach var in elas elas_SE elas_var publish year_publish_c site_m NPL_n NPL_y NPL_u active_n active_u job_n job_u non_haz nuclear air water element_u North_America Asia Other_continent cleanup0 cleanup2 cleanup3 cleanup_unclear dist_greater_mean sample_c sale_ind num_expl_c oth_disamen oth_amen access industry demoecon time_control direction interaction log_log OLS_spatial{
gen `var'3 = `var'/elas_SE_3
}

reg elas3 precision_3 elas_var3 year_publish_c3 site_m3 active_n3 active_u3 non_haz3 nuclear3 air3 water3 element_u3 cleanup03 cleanup23 cleanup33 cleanup_unclear3 dist_greater_mean3 sample_c3  demoecon3  interaction3 , nocons cluster(ID_Study)
outreg2 using "tables/Table 4.rtf", append dec(3) ctitle(G-S) 

*------------------------------------------------------------------------------*
*Replacing dist_greater_mean with dist_mean_c
*------------------------------------------------------------------------------*

quietly metareg elas elas_var publish year_publish_c site_m NPL_n NPL_y NPL_u active_n active_u job_n job_u non_haz nuclear air water element_u North_America Asia Other_continent cleanup0 cleanup2 cleanup3 cleanup_unclear dist_mean_c sample_c sale_ind num_expl_c oth_disamen oth_amen access industry demoecon time_control direction interaction log_log OLS_spatial, wsse(elas_SE)

scalar tau2 = e(tau2)
display tau2
gen elas_var_4= elas_var + tau2
gen elas_SE_4 = sqrt(elas_var_4)
gen precision_4= 1/(elas_SE_4)
gen precision_sq_4= 1/elas_var_4

foreach var in elas elas_SE elas_var publish year_publish_c site_m NPL_n NPL_y NPL_u active_n active_u job_n job_u non_haz nuclear air water element_u North_America Asia Other_continent cleanup0 cleanup2 cleanup3 cleanup_unclear dist_mean_c sample_c sale_ind num_expl_c oth_disamen oth_amen access industry demoecon time_control direction interaction log_log OLS_spatial{
gen `var'4 = `var'/elas_SE_4
}

reg elas4 precision_4 elas_var4 publish4 year_publish_c4 site_m4 NPL_n4 NPL_y4 NPL_u4 active_n4 active_u4 job_n4 job_u4 non_haz4 nuclear4 air4 water4 element_u4 North_America4 Asia4 Other_continent4 cleanup04 cleanup24 cleanup34 cleanup_unclear4 dist_mean_c4 sample_c4 sale_ind4 num_expl_c4 oth_disamen4 oth_amen4 access4 industry4 demoecon4 time_control4 direction4 interaction4 log_log4 OLS_spatial4, nocons cluster(ID_Study)
outreg2 using "tables/Table 4.rtf", append dec(3) ctitle(Mean distance)

*------------------------------------------------------------------------------*
*Only observations with socio-economic controls
*------------------------------------------------------------------------------*

quietly metareg elas elas_var publish year_publish_c site_m NPL_n NPL_y NPL_u active_n active_u job_n job_u non_haz nuclear air water element_u North_America Asia Other_continent cleanup0 cleanup2 cleanup3 cleanup_unclear dist_greater_mean sample_c sale_ind num_expl_c oth_disamen oth_amen access industry demoecon time_control direction interaction log_log OLS_spatial if demoecon==1, wsse(elas_SE) tau2test

scalar tau2 = e(tau2)
display tau2
gen elas_var_5= elas_var + tau2
gen elas_SE_5 = sqrt(elas_var_5)
gen precision_5= 1/(elas_SE_5)
gen precision_sq_5= 1/elas_var_5

foreach var in elas elas_SE elas_var publish year_publish_c site_m NPL_n NPL_y NPL_u active_n active_u job_n job_u non_haz nuclear air water element_u North_America Asia Other_continent cleanup0 cleanup2 cleanup3 cleanup_unclear dist_greater_mean sample_c sale_ind num_expl_c oth_disamen oth_amen access industry demoecon time_control direction interaction log_log OLS_spatial{
gen `var'5 = `var'/elas_SE_5
}

reg elas5 precision_5 elas_var5 publish5 year_publish_c5 site_m5 NPL_n5 NPL_y5 NPL_u5 active_n5 active_u5 job_n5 job_u5 non_haz5 nuclear5 air5 water5 element_u5 North_America5 Asia5 Other_continent5 cleanup05 cleanup25 cleanup35 cleanup_unclear5 dist_greater_mean5 sample_c5 sale_ind5 num_expl_c5 oth_disamen5 oth_amen5 access5 industry5 demoecon5 time_control5 direction5 interaction5 log_log5 OLS_spatial5 if demoecon==1, nocons cluster(ID_Study)
outreg2 using "tables/Table 4.rtf", append dec(3) ctitle(Socio-economic controls)

*------------------------------------------------------------------------------*
*Non-hazardous waste sites
*------------------------------------------------------------------------------*

quietly metareg elas elas_SE publish year_publish_c site_m  active_n active_u job_n job_u air water element_u North_America Asia Other_continent dist_greater_mean sample_c sale_ind num_expl_c oth_disamen oth_amen access industry demoecon time_control direction interaction log_log OLS_spatial if non_haz==1, wsse(elas_SE) tau2test

scalar tau2 = e(tau2)
display tau2
gen elas_var_6 = elas_var + tau2
gen elas_SE_6 = sqrt(elas_var_6)
gen precision_sq_6 = 1/elas_var_6
gen precision_6 = sqrt(precision_sq_6)

foreach var in elas elas_SE elas_var publish year_publish_c site_m NPL_n NPL_y NPL_u active_n active_u job_n job_u non_haz nuclear air water element_u North_America Asia Other_continent cleanup0 cleanup2 cleanup3 cleanup_unclear dist_greater_mean sample_c sale_ind num_expl_c oth_disamen oth_amen access industry demoecon time_control direction interaction log_log OLS_spatial{
gen `var'6 = `var'/elas_SE_6
}

reg elas6 precision_6 elas_SE6 publish6 year_publish_c6 site_m6 active_n6 active_u6 job_n6 job_u6 air6 water6 element_u6 North_America6 Asia6 Other_continent6 dist_greater_mean6 sample_c6 sale_ind6 num_expl_c6 oth_disamen6 oth_amen6 access6 industry6 demoecon6 time_control6 direction6 interaction6 log_log6 OLS_spatial6 if non_haz==1, nocons cluster(ID_Study)
outreg2 using "tables/Table 4.rtf", append dec(3) ctitle(Non-hazardous site)

*------------------------------------------------------------------------------*
*Waste sites on the NPL
*------------------------------------------------------------------------------*

quietly metareg elas elas_var publish year_publish_c site_m active_n active_u job_n job_u air water element_u cleanup0 cleanup2 cleanup3 cleanup_unclear dist_greater_mean sample_c sale_ind num_expl_c oth_disamen oth_amen access industry demoecon time_control direction interaction log_log OLS_spatial if NPL==1, wsse(elas_SE) tau2test

scalar tau2 = e(tau2)
display tau2
gen elas_var_7= elas_var + tau2
gen elas_SE_7 = sqrt(elas_var_7)
gen precision_7= 1/(elas_SE_7)
gen precision_sq_7= 1/elas_var_7

foreach var in elas elas_SE elas_var publish year_publish_c site_m active_n active_u job_n job_u air water element_u cleanup0 cleanup2 cleanup3 cleanup_unclear dist_greater_mean sample_c sale_ind num_expl_c oth_disamen oth_amen access industry demoecon time_control direction interaction log_log OLS_spatial{
gen `var'7 = `var'/elas_SE_7
}

reg elas7 precision_7 elas_var7 publish7 year_publish_c7 site_m7 active_n7 active_u7 job_n7 job_u7 air7 water7 element_u7 cleanup07 cleanup27 cleanup37 cleanup_unclear7 dist_greater_mean7 sample_c7 sale_ind7 num_expl_c7 oth_disamen7 oth_amen7 access7 industry7 demoecon7 time_control7 direction7 interaction7 log_log7 OLS_spatial7 if NPL==1, nocons cluster(ID_Study)
outreg2 using "tables/Table 4.rtf", append dec(3) ctitle(on NPL)



clear

